package com.fndsoft.police.xuancheng.ui.main;

import android.view.View;
import android.view.View.OnLayoutChangeListener;
import android.widget.EditText;
import android.widget.ScrollView;

import com.fndsoft.police.xuancheng.R;
import com.fndsoft.police.xuancheng.domain.ThreadMessage;
import com.fndsoft.police.xuancheng.net.OperateCode;
import com.fndsoft.police.xuancheng.ui.base.BaseAc;
import com.fndsoft.police.xuancheng.util.ValueUtil;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * 登录界面
 * 
 * @author LiangXiangJu
 * @creationTime 2014-7-31 下午2:11:27
 * @version
 */
public class LoginAc extends BaseAc {

	@Override
	public void doResponseFinished(OperateCode operateCode,
			ThreadMessage threadMessage) {
	}

	@ViewInject(R.id.svControl)
	private ScrollView svControl;
	@ViewInject(R.id.etUserName)
	private EditText etUserName;
	@ViewInject(R.id.etPwd)
	private EditText etPwd;

	@Override
	protected void installViews() {
		setContentView(R.layout.login_ac);
		ViewUtils.inject(this);

		// scrollView监听滚动
		svControl.addOnLayoutChangeListener(new OnLayoutChangeListener() {

			@Override
			public void onLayoutChange(View arg0, int arg1, int arg2, int arg3,
					int arg4, int arg5, int arg6, int arg7, int arg8) {
				if (arg8 > arg4) {
					svControl.scrollBy(0, arg8 - arg4);
				}
			}
		});
	}

	@OnClick(R.id.btnLogin)
	public void onClickLogin(View view) {
		// if (!checkData()) {
		// return;
		// }
		doLogin();
	}

	/**
	 * 登录
	 */
	private void doLogin() {
		//String userName = etUserName.getText().toString().trim();
		//String pwd = etPwd.getText().toString().trim();

		startCOActivity(MainAc.class);
		finish();
	}

	/**
	 * 登录检查
	 * 
	 * @author carlos carlosk@163.com
	 * @version
	 * @return
	 */
	private boolean checkData() {
		String userNmae = etUserName.getText().toString().trim();
		String pwd = etPwd.getText().toString().trim();
		if (ValueUtil.isStrEmpty(userNmae)) {
			//showToast(R.string.login_check_username_empty);
			return false;
		}
		if (ValueUtil.isStrEmpty(pwd)) {
			//showToast(R.string.login_check_password_empty);
			return false;
		}
		return true;
	}

	@Override
	protected void initData() {
	}

	@Override
	public boolean isCustomBackBtnEvent() {
		return true;
	}
}
